<?php 

/**
 * The log class offers a basic solution for keeping track of actions within
 * your web application. The object provides you with a stack to fill with
 * messages and keeps track of the timestamp, type of message, ipaddress of
 * visitor, script name where the logentry was triggered and the message
 * itself ofcourse.
 *
 * @author Dennis de Greef
 * @version 1.0
 */
class Log 
{    
    /**
     * The stack to which messages will be added along with other information
     * @var array
     */
    protected $messageStack = array();
    
    /**
     * The constructor for this class clears the stack so it can be used
     * for your own extend.
     *
     * @version 1.0
     * @return object
     */
    public function __construct() 
    {
        $this->clearStack();    
    }
    
    /**
     * Register a new message in the messagestack.
     *
     * @version 1.0
     * @param string $logMessage The message which should be added
     * @param string $messageType The type of message provided
     * @return void
     */
    public function record($logMessage = '', $messageType = 'information') 
    {
        $this->messageStack[] = array('timestamp' => time(),
                                      'type'      => $messageType,
                                      'ipaddress' => $_SERVER['REMOTE_ADDR'],
                                      'filename'  => $_SERVER['SCRIPT_NAME'],
                                      'message'   => $logMessage);
    }
    
    /**
     * Reset the stack to the default state, a clean array.
     *
     * @version 1.0
     * @return void
     */
    protected function clearStack() 
    {
        $this->messageStack = array();
    }
    
    /**
     * Retrieve the stack from the object
     *
     * @version 1.0
     * @return array
     */
    protected function getStack() 
    {
        return $this->messageStack;
    }
} 
